<template>
  <div class="btn-list__row">
    <div class="btn-list__item" v-for="item in list" :key="item.id">
      <!-- 如果链接包含 http 则使用 a 标签跳转 -->
      <a v-if="item.url && item.url.includes('http')" :href="item.url" class="size-normal btn-primary" :class="[item.type ? `btn-primary--${item.type}` : '']">
        <div class="btn-primary__text">{{ item.text }}</div>
        <span class="btn-primary__icon"></span>
      </a>
      <!-- 否则使用 button 并 emit handleClick 事件 -->
      <button v-else @click="handleClick(item.url || '')" class="size-normal btn-primary" :class="[item.type ? `btn-primary--${item.type}` : '']">
        <div class="btn-primary__text">{{ item.text }}</div>
        <span class="btn-primary__icon"></span>
      </button>
    </div>
  </div>
</template>

<script lang="ts" setup>
interface BtnItem {
  id: string | number;
  url?: string;
  type?: string;
  text: string;
}

defineProps<{
  list: BtnItem[]
}>();

const emit = defineEmits(['handleClick'])

const handleClick = (url: string) => {
  emit('handleClick', url)
}
</script>
<style lang="scss" scoped>
/* 从 main.scss 迁移的 .btn 样式 */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  background-color: transparent;
  cursor: pointer;
  position: relative;
  text-decoration: none;
  border: none;
  outline: none;
  color: #0048e8;
  color: var(--text-color, #0048e8);
}

.btn.btn__load-more {
  --text-color: #0032a0;
}

.btn--udrline {
  display: flex;
  flex-direction: column;
}

.btn--udrline--active:after,
.btn--udrline:hover:after {
  transform: scaleX(1);
}

.btn--udrline:after {
  content: "";
  width: 100%;
  height: 1px;
  border-radius: 1px;
  background-color: #0048e8;
  background-color: var(--text-color, #0048e8);
  transform: scaleX(0);
  transition: all .3s ease-in-out;
}

.btn--active,
.btn:hover {
  color: #0048e8;
  color: var(--text-color, #0048e8);
}

.btn--active .btn--udrline:after,
.btn:hover .btn--udrline:after {
  transform: scaleX(1);
} 
.btn-list__row {
  display: flex;
  align-items: center;
  margin-top: -16px;
  margin-left: -8px;
  margin-right: -8px;
}

@media (max-width: 767.98px) {
  .btn-list__row {
    flex-direction: column;
    margin-top: -8px;
  }
}

@media (max-width: 767.98px) {
  .btn-list__row.isnt-fullwidth {
    align-items: flex-start;
  }
}

.btn-list__row.isnt-fullwidth .btn-list__item {
  width: auto;
}

.btn-list__row.is-wrap {
  flex-wrap: wrap;
  flex-direction: row;
}

@media (max-width: 767.98px) {
  .btn-list__row.is-force-nowrap {
    flex-direction: row;
  }
}

.btn-list__item {
  padding-top: 16px;
  padding-left: 8px;
  padding-right: 8px;
}

@media (max-width: 767.98px) {
  .btn-list__item {
    padding-top: 8px;
    width: 100%;
  }
  .btn-list__item a,
  .btn-list__item button {
    width: 100%;
  }
}

.btn-list.center .btn-list__row {
  justify-content: center;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0032a0;
  background-color: var(--text-color--primary, #0032a0);
  padding: 11px 15px;
  min-width: 160px;
  border: none;
  border-radius: 4px;
  overflow: hidden;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(130,130,140,.12);
  position: relative;
  z-index: 1;
  white-space: nowrap;
}

.btn-primary.size-L {
  padding: 15px;
}

@media (max-width: 1023.98px) {
  .btn-primary.size-L {
    padding: 11px 15px;
    min-width: 100px;
  }
}

@media (max-width: 767.98px) {
  .btn-primary.size-L {
    padding: 8px 12px;
    min-width: 80px;
  }
}

@media (max-width: 1023.98px) {
  .btn-primary {
    padding: 11px 15px;
    min-width: 100px;
  }
}

@media (max-width: 767.98px) {
  .btn-primary {
    padding: 8px 12px;
    min-width: 80px;
  }
}

.btn-primary.size-XS {
  padding: 6px 12px;
  min-width: 100px;
  border-radius: 2px;
}

@media (max-width: 1023.98px) {
  .btn-primary.size-XS {
    padding: 6px 12px;
  }
}

@media (max-width: 767.98px) {
  .btn-primary.size-XS {
    padding: 6px 12px;
  }
}

.btn-primary.size-XS .btn-primary__icon,
.btn-primary.size-XS:active .btn-primary__icon,
.btn-primary.size-XS:hover .btn-primary__icon {
  display: none;
}

.btn-primary:before {
  content: "";
  display: block;
  background: #0048e8;
  position: absolute;
  width: 200%;
  height: 500%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: all .3s ease-in-out;
  z-index: -1;
  -webkit-clip-path: circle(100% at -80% 90%);
  clip-path: circle(100% at -80% 90%);
}

.btn-primary:hover:before {
  -webkit-clip-path: circle(100% at 50% 50%);
  clip-path: circle(100% at 50% 50%);
}

.btn-primary:hover .btn-primary__icon:before {
  transform: translate(-50%, -50%);
}

.btn-primary:hover .btn-primary__icon:after {
  transform: translate(150%, -50%);
}

.btn-primary:hover .btn-primary__icon:after,
.btn-primary:hover .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary:hover .btn-primary__icon:after,
  .btn-primary:hover .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary:active:before {
  -webkit-clip-path: circle(100% at -80% 90%);
  clip-path: circle(100% at -80% 90%);
}

.btn-primary:active .btn-primary__icon:before {
  transform: translate(-260%, -50%);
}

.btn-primary:active .btn-primary__icon:after {
  transform: translate(-50%, -50%);
}

.btn-primary:active .btn-primary__icon:after,
.btn-primary:active .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary:active .btn-primary__icon:after,
  .btn-primary:active .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary__text {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.285;
  letter-spacing: .04em;
  color: #fff;
  transition: color .3s ease-in-out;
}

@media (max-width: 1023.98px) {
  .btn-primary__text {
    line-height: 1.428;
  }
}

@media (max-width: 767.98px) {
  .btn-primary__text {
    line-height: 1.285;
  }
}

.btn-primary__icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  overflow: hidden;
  background-color: #fff;
  position: relative;
  margin-left: 7px;
  transition: background-color .3s ease-in-out;
  flex-shrink: 0;
}

@media (max-width: 767.98px) {
  .btn-primary__icon {
    width: 12px;
    height: 12px;
    margin-left: 6px;
  }
}

.btn-primary__icon:after,
.btn-primary__icon:before {
  content: "";
  width: 6px;
  height: 9px;
  position: absolute;
  top: 50%;
  left: 55%;
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
  transition: transform .3s ease-in-out;
}

@media (max-width: 767.98px) {
  .btn-primary__icon:after,
  .btn-primary__icon:before {
    width: 4.2px;
    height: 6px;
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary__icon:before {
  transform: translate(-260%, -50%);
}

.btn-primary__icon:after {
  transform: translate(-50%, -50%);
}

.btn-primary--white {
  background-color: #fff;
  box-shadow: none;
}

.btn-primary--white:before {
  background: #c1cede;
}

.btn-primary--white .btn-primary__text {
  color: #0032a0;
  color: var(--text-color--primary, #0032a0);
  transition: color .3s ease-in-out;
}

.btn-primary--white .btn-primary__icon {
  background-color: #0032a0;
  background-color: var(--text-color--primary, #0032a0);
}

.btn-primary--white .btn-primary__icon:after,
.btn-primary--white .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary--white .btn-primary__icon:after,
  .btn-primary--white .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary--white:active .btn-primary__icon:after,
.btn-primary--white:active .btn-primary__icon:before,
.btn-primary--white:hover .btn-primary__icon:after,
.btn-primary--white:hover .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary--white:active .btn-primary__icon:after,
  .btn-primary--white:active .btn-primary__icon:before,
  .btn-primary--white:hover .btn-primary__icon:after,
  .btn-primary--white:hover .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary--light {
  background-color: #f0f5fc;
  box-shadow: none;
}

.btn-primary--light:before {
  background: #c1cede;
}

.btn-primary--light .btn-primary__text {
  color: #0032a0;
  transition: color .3s ease-in-out;
}

.btn-primary--light .btn-primary__icon {
  background-color: #0032a0;
  background-color: var(--text-color--primary, #0032a0);
}

.btn-primary--light .btn-primary__icon:after,
.btn-primary--light .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary--light .btn-primary__icon:after,
  .btn-primary--light .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary--light:active .btn-primary__icon:after,
.btn-primary--light:active .btn-primary__icon:before,
.btn-primary--light:hover .btn-primary__icon:after,
.btn-primary--light:hover .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary--light:active .btn-primary__icon:after,
  .btn-primary--light:active .btn-primary__icon:before,
  .btn-primary--light:hover .btn-primary__icon:after,
  .btn-primary--light:hover .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary--blue {
  background-color: #001e60;
  background-color: var(--text-color--secondary, #001e60);
  box-shadow: none;
}

.btn-primary--blue:before {
  background: #0032a0;
  background: var(--text-color--primary, #0032a0);
}

.btn-primary--blue .btn-primary__text {
  color: #fff;
  transition: color .3s ease-in-out;
}

.btn-primary--blue .btn-primary__icon {
  background-color: #fff;
}

.btn-primary--blue .btn-primary__icon:after,
.btn-primary--blue .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary--blue .btn-primary__icon:after,
  .btn-primary--blue .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}

.btn-primary--blue:active .btn-primary__icon:after,
.btn-primary--blue:active .btn-primary__icon:before,
.btn-primary--blue:hover .btn-primary__icon:after,
.btn-primary--blue:hover .btn-primary__icon:before {
  background-image: url();
  background-position: 50%;
  background-size: cover;
  background-repeat: no-repeat;
  background-color: hsla(0,0%,100%,0);
}

@media (max-width: 767.98px) {
  .btn-primary--blue:active .btn-primary__icon:after,
  .btn-primary--blue:active .btn-primary__icon:before,
  .btn-primary--blue:hover .btn-primary__icon:after,
  .btn-primary--blue:hover .btn-primary__icon:before {
    background-image: url();
    background-position: 50%;
    background-size: cover;
    background-repeat: no-repeat;
    background-color: hsla(0,0%,100%,0);
  }
}
</style>